import {AGREE,DISAGREE,GIVEUP, ARRIVED,SUBMITDISAGREEREASON}  from '../constants/vote'
import api from '../services/api'
import {getRecommendPlayList} from './song'
export const agree = (payload, projectId, userId) => {
    return {
      type: AGREE,
      payload, projectId, userId
    }
  }
  export const disAgree = (payload, projectId, userId,recommend) => {
    return {
      type: DISAGREE,
      payload, projectId, userId,recommend,
    }
  }
  export const giveup = (payload, projectId, userId) => {
    return {
      type: GIVEUP,
      payload, projectId, userId
    }
  }
  export const arrived = (payload, projectId, userId) => {
    return {
      type: ARRIVED,
      payload, projectId, userId
    }
  }
  
export const submitDisagreeReason=(id, userId, disagreeReason,isagree)=>{
  return dispatch=>{
    console.log("entering submitDisagreeReason  提交否决原因")
      api.post('?updateVoteStatus',{'id':id,'userId':userId, 'suggest':disagreeReason,"isagree":isagree},
      "application/x-www-form-urlencoded"
      )
      .then((res)=>{
           console.log("submitDisagreeReason"+res)
           //刷新  
           getRecommendPlayList(userId)
          //  dispatch({
          //   type: SUBMITDISAGREEREASON,
          //   payload: {
          //      res
          //   }
          // })
          
      }).catch(function(e){
        console.log("提交失败："+e)
        //temp
        dispatch( {
            type: SUBMITDISAGREEREASON,
            payload:{
              id, userId, disagreeReason
            }
         })
      })
  }

}

//   export const getLikeMusicList = (payload) => {
//     const { id } = payload
//     return dispatch => {
//       api.get('/likelist', {
//         uid: id
//       }).then((res) => {
//         dispatch({
//           type: GETLIKEMUSICLIST,
//           payload: {
//             likeMusicList: res.data.ids || []
//           }
//         })
//       })
//     }
//   }
  
  
//   // 异步的action
// export function asyncAdd () {
//     return dispatch => {
//       setTimeout(() => {
//         dispatch(add())
//       }, 2000)
//     }
//   }
  
  